package org.dtrd.modules.content.articles.service.impl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.dtrd.modules.content.articles.entity.po.DtrdExtEmsContentArticle;
import org.dtrd.modules.content.articles.mapper.DtrdExtEmsContentArticleMapper;
import org.dtrd.modules.content.articles.service.IDtrdExtEmsContentArticleService;
import org.springframework.stereotype.Service;

/**
 * @author 萧
 * @date 2021-08-25 17:37:46
 **/
@Service
@DS("multi-datasource1")
public class DtrdExtEmsContentArticleServiceImpl extends ServiceImpl<DtrdExtEmsContentArticleMapper, DtrdExtEmsContentArticle> implements IDtrdExtEmsContentArticleService {

    @Override
    public void saveArticleInfo(Integer contentId, String content) {
        DtrdExtEmsContentArticle article = selectInfoByContentId(contentId);
        if (article != null) {
            baseMapper.saveArticleInfo(contentId,content);
        }else{
            article = new DtrdExtEmsContentArticle();
            article.setContent(content);
            article.setContentId(contentId);
            baseMapper.insert(article);
        }
    }

    private DtrdExtEmsContentArticle selectInfoByContentId(Integer contentId){
        LambdaQueryWrapper<DtrdExtEmsContentArticle> query = new LambdaQueryWrapper<>();
        query.eq(DtrdExtEmsContentArticle::getContentId, contentId).last(" limit 1 ");
        return baseMapper.selectOne(query);
    }

}
